package ru.braim.weather_app.services;

import jakarta.servlet.http.Cookie;
import org.springframework.stereotype.Service;

@Service
public class CookieService {

    private final AccountService accountService;

    public CookieService(AccountService accountService) {
        this.accountService = accountService;
    }


    public Cookie createCookie(String session) {
        Cookie cookie = new Cookie("id", session);
        cookie.setPath("/");
        return cookie;
    }

    public Cookie removeCookie() {
        Cookie cookie = new Cookie("id", null);
        cookie.setPath("/");
        return cookie;
    }


    public boolean checkAuthorizeCookie(String cookie) {
        if (cookie == null) {
            return false;
        }

        if (cookie.isEmpty()) {
            return false;
        }

        if (!accountService.checkCookieInAccount(cookie)) {
            return false;
        }

        return true;
    }


}
